package com.xy.controller;

import com.xy.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/4/10 22:02
 * @description
 */

@Controller
public class HelloController {
    @Autowired
    private HelloService helloService;

    @GetMapping("/hello")
    @ResponseBody
    public String hello(@RequestParam(value = "name",defaultValue = "world") String name) {
        Thread thread = Thread.currentThread();
        System.out.println(thread + "start...");
        try {
            sayHello();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return helloService.sayHello(name);


    }

    public void sayHello() throws InterruptedException {
        Thread.sleep(3000);
    }


    @GetMapping("/index")
    @ResponseBody
    public String index() {
        return "index";
    }

    @GetMapping("/success")
    public String success() {
        return "success";
    }

}
